package probe.logic;

/*
 */
public class Time implements Comparable<Time>{
	private int hour;
	private int minute;

	/*
	 * null constructor
	 */
	public Time() {
		
	}
	/*
	 * constructor for Time class from a string currently accepted format hhmm
	 * planned formats : hhAM/PM, hhmmAM/PM, hmm
	 */
	public Time(String timeString) throws NumberFormatException {
		if (timeString == null)
			return;
		this.hour = Integer.parseInt(timeString.substring(0, 2));
		if (timeString.charAt(2) != ':') {
			this.minute = Integer.parseInt(timeString.substring(2, 4));
		} else {
			this.minute = Integer.parseInt(timeString.substring(3, 5));
		}
	}
	/*
	 * constructor for Time class from 2 numbers: hour and minute
	 */
	public Time(int hour, int minute) {
		this.hour = hour;
		this.minute = minute;
	}
	/*
	 * getter methods
	 */
	public int getHour() {
		return hour;
	}

	public int getMinute() {
		return minute;
	}
	/*
	 * setter methods
	 */
	public void setHour(int newHour){
		this.hour = newHour;
	}
	public void setMinute(int newMinute){
		this.minute = newMinute;
	}
	/*
	 * process method
	 */
	public String timeToString() {
		String timeStr = null;
		timeStr = Integer.toString(minute);
		if (timeStr.length() == 1)
			timeStr = "0" + timeStr;
		timeStr = Integer.toString(hour) + ":" + timeStr;
		return timeStr;
	}
	public boolean isValidTime() {
		if ((0 > hour) || (hour > 23))
			return false;
		if ((0 > minute) || (minute > 59))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return timeToString();
	}
	public int compareTo(Time anotherTime){
		if (anotherTime.hour > this.hour) return -1;
		if (anotherTime.hour < this.hour) return 1;
		if (anotherTime.hour == this.hour) {
			if (anotherTime.minute > this.minute) return -1;
			if (anotherTime.minute < this.minute) return 1;
		}
		return 0;
	}


}
